/**
 * 
 */
package net.phoenix.repository;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Properties;

import javax.jcr.Value;
import javax.jcr.ValueFactory;
/**
 * @author lixf
 *
 */
public class RepositoryDescriptors {
	private ValueFactory factory;
	private Properties descriptors;
	
	public RepositoryDescriptors(ValueFactory factory) throws IOException{
		this.factory = factory;
		this.descriptors = new Properties();
		InputStream is = this.getClass().getClassLoader().getResourceAsStream("jigsaw-descriptors.properties");				
		descriptors.load(is);
		is.close();		
	}
	
	
	public String[] getDescriptorKeys() {
		Collection<String>  keys =this.descriptors.stringPropertyNames();
		return keys.toArray(new String[keys.size()]);
	}

	public boolean isStandardDescriptor(String key) {
		return true;
	}

	public boolean isSingleValueDescriptor(String key) {
		return true;
	}

	public Value getDescriptorValue(String key) {
		String value = this.descriptors.getProperty(key);
		if(value ==null)
			return null;
		return this.factory.createValue(this.descriptors.getProperty(key));
	}

	public Value[] getDescriptorValues(String key) {
		String value = this.descriptors.getProperty(key);
		if(value ==null)
			return null;
		return new Value[]{this.factory.createValue(this.descriptors.getProperty(key))};

	}

	public String getDescriptor(String key) {
		return this.descriptors.getProperty(key);
	}

	
}
